/*
 * The client message definition
 */

const VTC_FIRST =				1;
const VTC_DATA_RECV_ACK =			2; // with structure VtDataAck
const VTC_LOGIN =				3; // with structure VtLogin
const VTC_SET_SHARE_MEM =			4; // with structure VtShareMemSet
const VTC_GET_SHARE_MEM =			5; // with structure VtShareMemGet
const VTC_UPDATE_SHARE_MEM =			6;
const VTC_SET_SYS_TIME =			7; // with struct tm
const VTC_GET_SYS_TIME =			8;
const VTC_SET_SHARE_MEM_ALL =			9; // with structure VtShareMemsAccess
const VTC_GET_SHARE_MEM_ALL =			0xa;
const VTC_AUDIO_BROADCAST =			0xb; // with structure VtAudioBroadcast
const VTC_GET_INFO_TABLE =			0xc;
const VTC_SEND_PTZ_KEY =			0xd; // with structure VtSendPtzKey
const VTC_GET_SPINFO =				0xe;
const VTC_SW_UPGRADE =				0xf; // with structure VtSWUpgrade
const VTC_SET_ADDITIONAL_SHARE_MEMS =		0x10; // with structure VtAddShareMemsAccess
const VTC_GET_ADDITIONAL_SHARE_MEMS =		0x11; // with structure VtGetAddShareMems
const VTC_UPDATE_ADDITIONAL_SHARE_MEMS =	0x12;
const VTC_GET_POS_RECORD =			0x13; // with structure VtGetPOSRecord
const VTC_CHANGE_PLAYING_CHANNEL =		0x14; // with DWORD

const VTC_SET_EXTRA_V_STREAM =			0x28; // with structure VtSetExtraVStrm
const VTC_TRIGGER_ALARM_O =			0x2B; // with WORD
const VTC_GET_ALARM_O_STATE =			0x2C;
const VTC_POLL_STATUS =				0x2D; // with structure GetStatus
const VTC_REBOOT =				0x2F;
const VTC_GET_SYS_INFO =			0x30;
const VTC_GET_PTZ_INFO =			0x31;
const VTC_OPEN_PTZ_CTRL =			0x32;
const VTC_SET_PTZ_CMD =				0x33; // with structure VtPtzCommand
const VTC_SET_LOG_REFRESH =			0x34;
const VTC_GET_LOG =				0x35; // with structure VtGetLog
const VTC_OPEN_PLAYBACK =			0x36; // with structure VtOpenPlayback/VtOpenPlayback1
const VTC_CLOSE_PLAYBACK =			0x37;
const VTC_SET_PLAYBACK_CHANNEL =		0x38; // with structure VtOpenPlayback
const VTC_SET_PLAYBACK_CMD =			0x39; // with structure VtSetPlaybackCmd
const VTC_STREAM_CONNECT =			0x3A;
const VTC_STREAM_DISCONNECT =			0x3B;
const VTC_SET_LIVE_CHANNEL = 			0x3C; // with structure VtLiveChsParam
const VTC_WAP_SET_LIVE_CHANNEL =		0x3E; // with structure VtLiveChsParam
const VTC_WAP_GET_STREAM =			0x3F;
const VTC_GET_CMDS_LEVEL =			0x40;

const VTC_GET_DEV_TIME =			0x41; // HDDPlayer
const VTC_REGISTER_ALARM_NOTIFY = 		0x42;
const VTC_UNREGISTER_ALARM_NOTIFY = 		0x43;
const VTC_GET_ALARM_NOTIFY_STATUS = 		0x44;

const VTC_LAST =				0x44;

/*
 * The server message definition
 */

const VTS_FIRST =				0x51
const VTS_ACK_LOGIN =				0x52 // with structure AckVtLogin
const VTS_ACK_SET_SHARE_MEM =			0x53
const VTS_ACK_GET_SHARE_MEM =			0x54
const VTS_ACK_UPDATE_SHARE_MEM =		0x55
const VTS_ACK_SET_SYS_TIME =			0x56
const VTS_ACK_GET_SYS_TIME =			0x57 // with struct tm
const VTS_ACK_SET_SHARE_MEM_ALL =		0x58
const VTS_ACK_GET_SHARE_MEM_ALL =		0x59 // with structure VtShareMemsAccess
const VTS_ACK_AUDIO_BROADCAST =			0x5A
const VTS_AUDIO_BROADCAST_EJECT =		0x5B
const VTS_ACK_GET_INFO_TABLE =			0x5C // with structure VtInfoTable/VtInfoTable1
const VTS_ACK_SEND_PTZ_KEY =			0x5D
const VTS_ACK_GET_SPINFO =			0x5E // with structure VtGetSPInfo
const VTS_ACK_SW_UPGRADE =			0x5F
const VTS_ACK_SET_ADDITIONAL_SHARE_MEMS =	0x10 // be careful !!
const VTS_ACK_GET_ADDITIONAL_SHARE_MEMS =	0x61 // with structure VtAddShareMemsAccess
const VTS_ACK_UPDATE_ADDITIONAL_SHARE_MEMS =	0x62
const VTS_ACK_GET_POS_RECORD =			0x63 // with structure VtAckGetPOSRecord
const VTS_ACK_CHANGE_PLAYING_CHANNEL =		0x64
const VTS_ACK_SET_EXTRA_V_STREAM =		0x78
const VTS_ACK_TRIGGER_ALARM_O =			0x7A
const VTS_ACK_GET_ALARM_O_STATE =		0x7B
const VTS_ACK_POLL_STATUS =			0x7C // with structure EventStatus/EventStatus2
const VTS_ACK_REBOOT =				0x7E
const VTS_ACK_GET_SYS_INFO =			0x7F // with structure SystemInfo
const VTS_ACK_GET_PTZ_INFO =			0x80 // with structure VtPtzInfo
const VTS_ACK_OPEN_PTZ_CTRL =			0x81
const VTS_ACK_SET_PTZ_CMD =			0x82
const VTS_ACK_GET_LOG =				0x84 // with structure VtAckGetLog/VtAckGetLog2
const VTS_ACK_OPEN_PLAYBACK =			0x85
const VTS_ACK_CLOSE_PLAYBACK =			0x86
const VTS_ACK_SET_PLAYBACK_CHANNEL =		0x87
const VTS_ACK_SET_PLAYBACK_CMD =		0x88
const VTS_ACK_STREAM_CONNECT =			0x89
const VTS_ACK_STREAM_DISCONNECT =		0x8A
const VTS_ACK_SET_LIVE_CHANNEL =		0x8B
const VTS_ACK_WAP_SET_LIVE_CHANNEL =		0x8D
const VTS_ACK_WAP_GET_STREAM =			0x8E
const VTS_ACK_GET_CMDS_LEVEL =			0x8F
const VTS_EVENT_NOTIFY =			0x91 // with structure EventNotify/EventNotify2
const VTS_LAST =				0x91

var header = function(ack, msgID, length) {
	this.data = new Buffer(7);
	this.data.fill(0);
	if (ack != null && msgID && length != null) {
		if (ack) {
			this.data.writeUInt8(0x1, 0);
		} else {
			this.data.writeUInt8(0x0, 0);
		}
		this.data.writeUInt16LE(msgID, 1);
		this.data.writeUInt32LE(length, 3);
	} else {
		console.log('plz input ack, msgID, length');
		return;
	}
}

module.exports = {
	VTC_FIRST :				VTC_FIRST,
	VTC_DATA_RECV_ACK :			VTC_DATA_RECV_ACK,
	VTC_LOGIN :				VTC_LOGIN,
	VTC_SET_SHARE_MEM :			VTC_SET_SHARE_MEM,
	VTC_GET_SHARE_MEM :			VTC_GET_SHARE_MEM,
	VTC_UPDATE_SHARE_MEM :			VTC_UPDATE_SHARE_MEM,
	VTC_SET_SYS_TIME :			VTC_SET_SYS_TIME,
	VTC_GET_SYS_TIME :			VTC_GET_SYS_TIME,
	VTC_SET_SHARE_MEM_ALL :			VTC_SET_SHARE_MEM_ALL,
	VTC_GET_SHARE_MEM_ALL :			VTC_GET_SHARE_MEM_ALL,
	VTC_AUDIO_BROADCAST :			VTC_AUDIO_BROADCAST,
	VTC_GET_INFO_TABLE :			VTC_GET_INFO_TABLE,
	VTC_SEND_PTZ_KEY :			VTC_SEND_PTZ_KEY,
	VTC_GET_SPINFO :			VTC_GET_SPINFO,
	VTC_SW_UPGRADE :			VTC_SW_UPGRADE,
	VTC_SET_ADDITIONAL_SHARE_MEMS :		VTC_SET_ADDITIONAL_SHARE_MEMS,
	VTC_GET_ADDITIONAL_SHARE_MEMS :		VTC_GET_ADDITIONAL_SHARE_MEMS,
	VTC_UPDATE_ADDITIONAL_SHARE_MEMS :	VTC_UPDATE_ADDITIONAL_SHARE_MEMS,
	VTC_GET_POS_RECORD :			VTC_GET_POS_RECORD,
	VTC_CHANGE_PLAYING_CHANNEL :		VTC_CHANGE_PLAYING_CHANNEL,
	VTC_SET_EXTRA_V_STREAM :		VTC_SET_EXTRA_V_STREAM,
	VTC_TRIGGER_ALARM_O :			VTC_TRIGGER_ALARM_O,
	VTC_GET_ALARM_O_STATE :			VTC_GET_ALARM_O_STATE,
	VTC_POLL_STATUS :			VTC_POLL_STATUS,
	VTC_REBOOT :				VTC_REBOOT,
	VTC_GET_SYS_INFO :			VTC_GET_SYS_INFO,
	VTC_GET_PTZ_INFO :			VTC_GET_PTZ_INFO,
	VTC_OPEN_PTZ_CTRL :			VTC_OPEN_PTZ_CTRL,
	VTC_SET_PTZ_CMD :			VTC_SET_PTZ_CMD,
	VTC_SET_LOG_REFRESH :			VTC_SET_LOG_REFRESH,
	VTC_GET_LOG :				VTC_GET_LOG,
	VTC_OPEN_PLAYBACK :			VTC_OPEN_PLAYBACK,
	VTC_CLOSE_PLAYBACK :			VTC_CLOSE_PLAYBACK ,
	VTC_SET_PLAYBACK_CHANNEL :		VTC_SET_PLAYBACK_CHANNEL,
	VTC_SET_PLAYBACK_CMD :			VTC_SET_PLAYBACK_CMD,
	VTC_STREAM_CONNECT :			VTC_STREAM_CONNECT,
	VTC_STREAM_DISCONNECT :			VTC_STREAM_DISCONNECT,
	VTC_SET_LIVE_CHANNEL : 			VTC_SET_LIVE_CHANNEL,
	VTC_WAP_SET_LIVE_CHANNEL :		VTC_WAP_SET_LIVE_CHANNEL,
	VTC_WAP_GET_STREAM :			VTC_WAP_GET_STREAM,
	VTC_GET_CMDS_LEVEL :			VTC_GET_CMDS_LEVEL,
	VTC_LAST :				VTC_LAST,

	VTS_FIRST :				VTS_FIRST,
	VTS_ACK_LOGIN :				VTS_ACK_LOGIN,
	VTS_ACK_SET_SHARE_MEM :			VTS_ACK_SET_SHARE_MEM,
	VTS_ACK_GET_SHARE_MEM :			VTS_ACK_GET_SHARE_MEM,
	VTS_ACK_UPDATE_SHARE_MEM :		VTS_ACK_UPDATE_SHARE_MEM,
	VTS_ACK_SET_SYS_TIME :			VTS_ACK_SET_SYS_TIME,
	VTS_ACK_GET_SYS_TIME :			VTS_ACK_GET_SYS_TIME,
	VTS_ACK_SET_SHARE_MEM_ALL :		VTS_ACK_SET_SHARE_MEM_ALL,
	VTS_ACK_GET_SHARE_MEM_ALL :		VTS_ACK_GET_SHARE_MEM_ALL,
	VTS_ACK_AUDIO_BROADCAST :		VTS_ACK_AUDIO_BROADCAST,
	VTS_AUDIO_BROADCAST_EJECT :		VTS_AUDIO_BROADCAST_EJECT,
	VTS_ACK_GET_INFO_TABLE :		VTS_ACK_GET_INFO_TABLE,
	VTS_ACK_SEND_PTZ_KEY :			VTS_ACK_SEND_PTZ_KEY,
	VTS_ACK_GET_SPINFO :			VTS_ACK_GET_SPINFO,
	VTS_ACK_SW_UPGRADE :			VTS_ACK_SW_UPGRADE,
	VTS_ACK_SET_ADDITIONAL_SHARE_MEMS :	VTS_ACK_SET_ADDITIONAL_SHARE_MEMS,
	VTS_ACK_GET_ADDITIONAL_SHARE_MEMS :	VTS_ACK_GET_ADDITIONAL_SHARE_MEMS,
	VTS_ACK_UPDATE_ADDITIONAL_SHARE_MEMS :	VTS_ACK_UPDATE_ADDITIONAL_SHARE_MEMS,
	VTS_ACK_GET_POS_RECORD :		VTS_ACK_GET_POS_RECORD,
	VTS_ACK_CHANGE_PLAYING_CHANNEL :	VTS_ACK_CHANGE_PLAYING_CHANNEL,
	VTS_ACK_SET_EXTRA_V_STREAM :		VTS_ACK_SET_EXTRA_V_STREAM,
	VTS_ACK_TRIGGER_ALARM_O :		VTS_ACK_TRIGGER_ALARM_O,
	VTS_ACK_GET_ALARM_O_STATE :		VTS_ACK_GET_ALARM_O_STATE,
	VTS_ACK_POLL_STATUS :			VTS_ACK_POLL_STATUS,
	VTS_ACK_REBOOT :			VTS_ACK_REBOOT,
	VTS_ACK_GET_SYS_INFO :			VTS_ACK_GET_SYS_INFO,
	VTS_ACK_GET_PTZ_INFO :			VTS_ACK_GET_PTZ_INFO,
	VTS_ACK_OPEN_PTZ_CTRL :			VTS_ACK_OPEN_PTZ_CTRL,
	VTS_ACK_SET_PTZ_CMD :			VTS_ACK_SET_PTZ_CMD,
	VTS_ACK_GET_LOG :			VTS_ACK_GET_LOG,
	VTS_ACK_OPEN_PLAYBACK :			VTS_ACK_OPEN_PLAYBACK,
	VTS_ACK_CLOSE_PLAYBACK :		VTS_ACK_CLOSE_PLAYBACK,
	VTS_ACK_SET_PLAYBACK_CHANNEL :		VTS_ACK_SET_PLAYBACK_CHANNEL,
	VTS_ACK_SET_PLAYBACK_CMD :		VTS_ACK_SET_PLAYBACK_CMD,
	VTS_ACK_STREAM_CONNECT :		VTS_ACK_STREAM_CONNECT,
	VTS_ACK_STREAM_DISCONNECT :		VTS_ACK_STREAM_DISCONNECT,
	VTS_ACK_SET_LIVE_CHANNEL :		VTS_ACK_SET_LIVE_CHANNEL,
	VTS_ACK_WAP_SET_LIVE_CHANNEL :		VTS_ACK_WAP_SET_LIVE_CHANNEL,
	VTS_ACK_WAP_GET_STREAM :		VTS_ACK_WAP_GET_STREAM,
	VTS_ACK_GET_CMDS_LEVEL :		VTS_ACK_GET_CMDS_LEVEL,
	VTS_EVENT_NOTIFY :			VTS_EVENT_NOTIFY,
	VTS_LAST :				VTS_LAST,

	header :				header,
	CMDID :					7, // 8th byte of response data
	CMDSUCCESS :				'\x00',
	CMDFAILED :				'\xff',
};
